package com.xiaolin.ssosystem.utils;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.util.Objects;
import java.util.Stack;

/**
 * @author xiaolin
 * @description 描述
 * @since 2024/10/9
 */
public class ContextUtil {
    /**
     * 获取用户token
     *
     * @param request
     * @param userToken
     * @return
     */
    public static String getToken(HttpServletRequest request, String userToken) {
        Cookie[] cookies = request.getCookies();
        if(Objects.isNull(cookies)) {
            return "";
        }
        String token = "";
        for (Cookie cookie : cookies) {
            if (userToken.equals(cookie.getName())) {
                token = cookie.getValue();
                break;
            }
        }
        return token;
    }
}
